/**
 * 
 */

package com.pp.admin.common.client.helper;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.pp.admin.common.client.i18.I18;

/**
 * @author pandurang
 */
public class ConfirmWindow extends DialogBox implements I18 {
	
	private ConfirmHandler	parent	= null;
	
	public ConfirmWindow( ConfirmHandler parent, String question ) {

		super( false, true );
		this.parent = parent;
		setText( myConstants.confirm() );
		setGlassEnabled( true );
		// Enable animation.
		setAnimationEnabled( true );
		HorizontalPanel hPanel = new HorizontalPanel();
		Image qimg = new Image( Resource.QUESTION_IMG_URL );
		qimg.setHeight( Resource.DIALOG_IMG_HEIGHT );
		qimg.setWidth( Resource.DIALOG_IMG_WIDTH );
		hPanel.add( qimg );
		VerticalPanel vPanel = new VerticalPanel();
		vPanel.add( new HTML( question ) );
		HorizontalPanel btnPanel = new HorizontalPanel();
		Button btnOk = new Button( myConstants.ok() );
		btnOk.addClickHandler( new ClickHandler() {
			
			@Override
			public void onClick( ClickEvent event ) {

				ConfirmWindow.this.hide();
				ConfirmWindow.this.parent.confirm( true );
			}
		} );
		btnPanel.add( btnOk );
		Button btnCancel = new Button( myConstants.cancel() );
		btnCancel.addClickHandler( new ClickHandler() {
			
			@Override
			public void onClick( ClickEvent event ) {

				ConfirmWindow.this.hide();
				ConfirmWindow.this.parent.confirm( false );
			}
		} );
		btnPanel.add( btnCancel );
		vPanel.add( btnPanel );
		hPanel.add( vPanel );
		this.setWidget( hPanel );
		this.center();
	}
}
